<?php
namespace app\api\controller;
use think\Db;
class Login{
	public function login(){
		$parkingCode=request()->get("parkingCode");;
		$password=request()->get("password");
		if(empty($parkingCode)){
			return '{"resultCode": "400","errmsg": "停车场id不能为空"}';
			return '{"resultCode": "200","msg": "操作成功"}';
		}
		if(empty($password)){
			return '{"resultCode": "400","errmsg": "密码不能为空"}';
			return '{"resultCode": "200","msg": "操作成功"}';
		}
		//查询车场信息
		$parkinginfo=Db::table("parkinglotinfo")->where("parking_id",$parkingCode)->find();
		if(empty($parkinginfo)){
			return '{"resultCode": "400","errmsg": "用户名和密码不正确"}';
		}
		$token=md5(time().mt_rand(0,1000));
		$res=Db::table("parkinglotinfo")->where("id",$parkinginfo["id"])->update(["token"=>$token,"token_ctime"=>time()]);
		if($res){
			return '{"resultCode": "200","msg": "操作成功","token":"'.$token.'"}';
		}else{
			return '{"resultCode": "500","errmsg": "token获取失败"}';
		}
		
	}
}